//
//  ProtocolAndBlockViewController.swift
//  swift各类控件集锦
//
//  Created by iosdev1 on 2017/5/23.
//  Copyright © 2017年 zyy. All rights reserved.
//

import UIKit



class ProtocolAndBlockViewController: ZyBaseViewController,ProtocolDelegate {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        let  btnProtocol = UIButton.init(frame: CGRect(x:10, y:100, width:100, height:100))
        self.view.addSubview(btnProtocol)
        btnProtocol.setTitle("设置Protocol", for: UIControlState.normal)
        btnProtocol.backgroundColor = UIColor.black
        btnProtocol.addTarget(self, action: #selector(btnProtocolClick(btn:)), for: UIControlEvents.touchUpInside)
        
        let  btnClosure = UIButton.init(frame: CGRect(x:10, y:300, width:100, height:100))
        self.view.addSubview(btnClosure)
        btnClosure.setTitle("设置Closure", for: UIControlState.normal)
        btnClosure.backgroundColor = UIColor.black
        btnClosure.addTarget(self, action: #selector(btnClosureClick(btn:)), for: UIControlEvents.touchUpInside)
    }

    func btnProtocolClick(btn:UIButton) -> Void {
        let pab = PABViewController()
        pab.delegate = self
        self.navigationController?.pushViewController(pab, animated: true)
    }
    
    func btnClosureClick(btn:UIButton) -> Void {
        let pab = PABViewController()
        
        pab.pabClosure = {(data)in
            let dataStr:String = String(data)
            echo(data: "这是闭包传过来的值:\(dataStr)")
            return "调用闭包Cloure成功"
        }                
        self.navigationController?.pushViewController(pab, animated: true)
    }
    
    
//    实现自定义代理方法
    func protocolDelegateFuncOne(val: String) {
        print("代理方法1:\(val)")
    }
    
    func protocolDelegateFuncTwo(val: Dictionary<String, Any>) {
        print("代理方法2:\(val)")
    }
    
    func protocolDelegateFuncThree(val: Array<String>) -> String {
        print("代理方法3:\(val)")
        
        return "代理方法3"
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
